<template>
	<el-drawer title="任务延期审批" v-model="visible" :size="800" destroy-on-close @closed="$emit('closed')">
		<el-container v-loading="loading">
			<el-main>
				<el-form>
					<div style="text-align: center;font-size: 18px;font-weight: 600;margin-bottom: 15px;">
						{{title}}
					</div>
					<el-form-item label="延期事由" prop="content">{{form.content}}
					</el-form-item>
					<el-form-item label="延期日期" prop="delayTime">{{form.delayTime}}
					</el-form-item>
					<el-form-item label="备注" prop="remark">{{form.remark}}
					</el-form-item>
					<el-form-item label="相关附件" v-if="form.attachId!=''">
						<attach-menu :attachIds="form.attachId" :roleFlag="1" :preview="true"></attach-menu>
					</el-form-item>
					<el-divider content-position="center">审批信息</el-divider>
					<el-form-item label="审批意见" prop="ideaText">
						<el-input v-model="form.ideaText" maxlength="380" clearable type="textarea"></el-input>
					</el-form-item>
				</el-form>
				<el-footer style="text-align: center;">
					<el-button @click="visible=false">关闭</el-button>
					<el-button type="primary" :loading="isSaveing" @click="submit()">审 批</el-button>
				</el-footer>
			</el-main>
		</el-container>
	</el-drawer>
</template>

<script>
import AttachMenu from '@/views/module/attachMenu'
export default {
	emits: ['success', 'closed'],
	components: {
		AttachMenu
	},
	data() {
		return {
			loading: false,
			title:"",
			form: {
				delayId:"",
				content:"",
				delayTime:"",
				attachId: "",
				remark: "",
				ideaText:"",
			},
			visible: false,
			isSaveing: false,
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open(){
			this.visible = true;
			return this;
		},
		submit()
		{
			this.isSaveing = true;
			this.$confirm('请您审批是否通过?', '提示', {
				distinguishCancelAndClose:true,
				confirmButtonText: '通过',
				cancelButtonText: '不通过',
				type: 'warning'
			}).then(async () => {
				var res = await this.$API.supervision.supervisionDelay.updateSupervisionDelay.post({delayId: this.form.delayId, passStatus: "1",ideaText:this.form.ideaText});
				if (res.code == 200) {
					this.$emit('success')
				} else {
					this.$alert(res.message, "提示", {type: 'error'})
				}
			}).catch(async (action) => {
				if(action === 'cancel') {
					var res = await this.$API.supervision.supervisionDelay.updateSupervisionDelay.post({delayId: this.form.delayId, passStatus: "2",ideaText:this.form.ideaText});
					if (res.code == 200) {
						this.$emit('success')
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			});
			this.isSaveing = false;
			this.visible = false;
		},
		setData(data){
			this.title = data.title
			this.form.delayId = data.delayId
			this.form.content = data.content
			this.form.remark = data.remark
			this.form.attachId = data.attachId
			this.form.delayTime = data.delayTime
		},
	}
}
</script>

<style>
</style>
